Skip to content

test(audio): stop asserting statechange order on the raw binding - #205

Merged
triniwiz merged 1 commit into
masterfrom
fix/audio-statechange-order
Nov 12, 2026
Merged

triniwiz merged 1 commit into
masterfrom
fix/audio-statechange-order

Conversation

@triniwiz

Copy link
Copy Markdown
Member

The realtime context test in crates/audio-context-napi fails intermittently, and it is blocking the 3.0.5 npm release (Windows x64).

Cause

The raw binding delivers statechange through a threadsafe function. suspend()/resume()/close() resolve through an AsyncTask. They reach JS through separate libuv queues, so the handler can run after the promise has settled and read a later state. That is how the test saw running,running,running,closed with no suspended.

Chrome's order (event before the promise continuation) is handled in the wrapper, packages/audio-context/napi.ts (_changeState / _syncState), and late native events are dropped there. The test called the binding directly and expected an order the binding never guaranteed. Copying the wrapper's logic into Rust would add nothing for users.

Change

  • The test still checks context.state after each await. That is reliable because the native calls block until the render thread has made the change.
  • It waits for the closed event instead of sleeping 50 ms, then checks that at least 3 state events fired and the last one was closed.
  • The Linux-only todo is gone, since the same race also hit Windows x64.
  • setOnstatechange's doc comment now says the callback is not ordered with the promises.

Testing

On Linux x64, with all 16 cores kept busy:

Test Runs Failures
Previous version (todo removed) 150 5
This version 150 0

The full audio suite passes, 11/11.

The binding's statechange (a threadsafe function) and the
suspend/resume/close promises (AsyncTasks) reach JS through separate
libuv queues, so the handler can run after a promise settles and read a
later state. The wrapper in napi.ts orders them as Chrome does; the
binding never did. Check the final state instead, wait for the closed
event rather than sleeping, and drop the Linux-only todo, since the
same race also failed on Windows x64.
@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e6021e1f-1fbd-4f2c-9088-365c94d2f383

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@triniwiz
triniwiz merged commit 955352b into master Nov 12, 2026
6 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant